<template>
  <div class="w-full">
    <el-row :gutter="24">
      <el-col style="flex: 1">
        <el-form ref="formRef" :model="props.model" :label-width="80" :label-position="'left'">
          <el-row :gutter="24">
            <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="6" v-for="item in allSlotsName" :key="item">
              <slot :name="item"></slot>
            </el-col>
          </el-row>
        </el-form>
      </el-col>
      <el-divider :style="{ height: allSlotsName.length <= 3 ? '42px' : '84px', 'min-height': '14px' }" direction="vertical" />
      <el-col class="custom-col">
        <el-space
          direction="vertical"
          :class="['custom-space', allSlotsName.length <= 3 ? 'custom-space-one' : '']"
          :size="[allSlotsName.length <= 3 ? 12 : 0, 18]"
        >
          <slot name="btnGroup"></slot>
        </el-space>
      </el-col>
    </el-row>
    <el-divider border-style="double" style="margin-top: 0" />
  </div>
</template>

<script lang="ts" setup>
import { FormInstance } from "element-plus";

defineOptions({
  name: "SearchCard"
});

const props = defineProps<{ model: any }>();
const formRef = ref<FormInstance>();
const slots = useSlots();
const allSlotsName = computed(() => Object.keys(slots).filter(item => item !== "btnGroup"));

const resetFields = () => {
  console.log("resetFields");
  formRef.value?.resetFields();
};

defineExpose({
  resetFields
});
</script>

<style lang="scss" scoped>
.custom-col {
  flex: 0 0 86px;
  text-align: right;
}
.custom-space {
  width: 100%;
  &.custom-space-one {
    flex-direction: row;
    gap: 18px 12px;
  }
}
</style>
